<?php

namespace app\admin\service;

use app\common\model\trSystemSet;
use app\common\util\ErrorCode;

/**
 * Class Auth
 * @package app\admin\service
 * 小程序服务类
 */
class WxAppService
{
    private $returnData;
    private $params;
    private $mall_id = 0;

    public function __construct($data, $params){
        $this->returnData = $data;
        $this->params = $params;
        $this->mall_id = request()->mallData["id"];
    }

    // 小程序设置
    public function getSetting(){
        $status = trSystemSet::getValue("wxAppDriverOnlineStatus");
        $data["onlineStatus"] = isset($status["status"]) ? $status["status"] : '1';
        $status = trSystemSet::getValue("wxAppWalletStatus");
        $data["walletStatus"] = isset($status["status"]) ? $status["status"] : '1';
        $this->returnData["data"] = $data;
        return $this->returnData;
    }

    // 小程序设置
    public function getSaveSetting(){
        $result = trSystemSet::toSave(["status" => isset($this->params["walletStatus"]) ? $this->params["walletStatus"] : '1'], "wxAppWalletStatus");
        if(!$result){
            $this->returnData = ErrorCode::$errorCode["fail"];
        }
        $result = trSystemSet::toSave(["status" => isset($this->params["onlineStatus"]) ? $this->params["onlineStatus"] : '1'], "wxAppDriverOnlineStatus");
        if(!$result){
            $this->returnData = ErrorCode::$errorCode["fail"];
        }
        return $this->returnData;
    }

    // 获取小程序标题
    public function getWxAppTitle(){
        $data = trSystemSet::getValue("wxAppTitleSetting");
        $data["mainColor"] = isset($data["mainColor"]) ? $data["mainColor"] : '#19C5F4';
        $data["navbarShowMode"] = isset($data["navbarShowMode"]) ? $data["navbarShowMode"] : 'FOUR_ITEM_LINE';
        $data["wxappTitle"] = isset($data["wxappTitle"]) ? $data["wxappTitle"] : '跨境租车';
        $this->returnData["data"] = $data;
        return $this->returnData;
    }

    // 更新小程序标题
    public function updateWxAppTitle(){
        $result = trSystemSet::toSave([
            "mainColor" => isset($this->params["mainColor"]) ? $this->params["mainColor"] : '#19C5F4',
            "wxappTitle" => isset($this->params["wxappTitle"]) ? $this->params["wxappTitle"] : '跨境租车',
            "navbarShowMode" => isset($this->params["navbarShowMode"]) ? $this->params["navbarShowMode"] : 'FOUR_ITEM_LINE',
        ], "wxAppTitleSetting");
        if(!$result){
            $this->returnData = ErrorCode::$errorCode["fail"];
        }
        return $this->returnData;
    }

    // 获取宣传语
    public function getSlogan(){
        $data = trSystemSet::getValue("wxAppSlogan");
        $data["content"] = isset($data["content"]) ? $data["content"] : '九龙, 机场, 迪士尼直达';
        $this->returnData["data"] = $data;
        return $this->returnData;
    }

    // 更新宣传语
    public function updateSlogan(){
        $result = trSystemSet::toSave([
            "content" => isset($this->params["content"]) ? $this->params["content"] : '九龙, 机场, 迪士尼直达',
        ], "wxAppSlogan");
        if(!$result){
            $this->returnData = ErrorCode::$errorCode["fail"];
        }
        return $this->returnData;
    }
}